package cn.schoolwow.quickdao.module.operation.flow.generateEntity;

import cn.schoolwow.quickdao.domain.entity.Entity;
import cn.schoolwow.quickdao.module.operation.flow.generateEntity.single.*;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;

import java.util.List;

public class TraverseDatabaseEntityFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        List<Entity> databaseEntityList = (List<Entity>) flowContext.checkData("databaseEntityList");

        for(Entity databaseEntity:databaseEntityList){
            flowContext.startFlow(new SetEntityClassNameFlow())
                    .next(new CreateEntityClassDirectoryFlow())
                    .next(new GenerateClassTableFlow())
                    .next(new GenerateClassTablePropertyFlow())
                    .next(new GenerateGetSetMethodFlow())
                    .next(new WriteClassToFileFlow())
                    .putCurrentCompositeFlowData("databaseEntity", databaseEntity)
                    .putTemporaryData("builder", new StringBuilder())
                    .execute();
        }
    }

    @Override
    public String name() {
        return "遍历数据库表列表";
    }
}
